<?php

namespace common\models\Activity;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;
use yii\web\IdentityInterface;
use common\models\grade\Grade;
use common\models\Label\Label;
use common\models\Guest\Guest;
use common\models\customset\CustomSet;
/**
 * This is the model class for table "activity".
 *
 * @property integer $ac_id
 * @property string $ac_name
 * @property string $ac_label
 * @property string $ac_desciption
 * @property string $start_time
 * @property string $end_time
 * @property string $ac_man
 * @property string $g_id
 * @property string $ac_phone
 * @property string $ac_number
 * @property integer $ac_status
 * @property string $ac_arrange
 * @property string $ac_field
 * @property string $ac_sponsor
 * @property integer $la_id
 */
class Activity extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    

    const ACSTATUS_DELETED = 0;//未发布
    const ACSTATUS_ACTIVE = 10;//已发布
    const DIS_ACTIVE = 0; //未进行
    const DIS_DELETED = 20; //进行中
    const DIS_SUCCESS =40; //已结束
    private $_statusLabel;
    private $_gradeLabel;

    public static function tableName()
    {
        return 'activity';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['start_time', 'end_time'], 'safe'],
            [['ac_status','ac_display'], 'required'],
            [['ac_status','ac_display','la_id','g_id','cu_id'], 'integer'],
            [['ac_name', 'ac_man', 'ac_phone'], 'string', 'max' => 60],
            [['ac_desciption', 'ac_number', 'ac_arrange', 'ac_field','ac_cost','ac_baoming', 'ac_sponsor'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'ac_id' => Yii::t('app', 'ID'),
            'ac_name' => Yii::t('app', '活动标题'),
   
            'la_id' => Yii::t('app', '活动标签'),
            'ac_desciption' => Yii::t('app', '活动描述'),
            'start_time' => Yii::t('app', '开始时间'),
            'end_time' => Yii::t('app', '结束时间'),
            'ac_man' => Yii::t('app', '内部联系人'),
            'g_id' => Yii::t('app', '演讲嘉宾'),
			'cu_id' => Yii::t('app', '报名类型'),
            'ac_phone' => Yii::t('app', '联系方式'),
            'ac_number' => Yii::t('app', '参与人数'),
            'ac_status' => Yii::t('app', '发布状态'),
            'ac_display' => Yii::t('app', '进行状态'),
			'ac_cost' => Yii::t('app', '活动费用'),
            'ac_arrange' => Yii::t('app', '日程安排'),
            'ac_field' => Yii::t('app', '场地'),
            'ac_baoming' => Yii::t('app', '报名信息'),
            'ac_sponsor' => Yii::t('app', '赞助商'),
            
        ];
    }


    /**
     * @活动是否发布
     */
     public function getStatusLabel()
    {
        if ($this->_statusLabel === null) {
            $statuses = self::getArrayStatus();
            //var_dump($statuses);die();
            $this->_statusLabel = array_key_exists($this->ac_status,self::getArrayStatus()) ? $statuses[$this->ac_status] : '无';
        }
        return $this->_statusLabel;
    }
   /**
     * @inheritdoc
     */
    public static function getArrayStatus()
    {
        return [
            self::ACSTATUS_ACTIVE => Yii::t('app', '已发布'),
            self::ACSTATUS_DELETED => Yii::t('app', '未发布'),

        ];
    }
    /**
     * @活动是否进行
     */
    public function getGradeLabel()
    {

        if ($this->_gradeLabel === null) {
            $grade = self::getArrayGrade();
            //var_dump($grade);die();
            $this->_gradeLabel =  array_key_exists($this->ac_display,self::getArrayGrade()) ? $grade[$this->ac_display] : '无';
            //var_dump( $this->_gradeLabel);die();
        }
        return $this->_gradeLabel;
    }
    public static function getArrayGrade()
    {
        return [
            self::DIS_ACTIVE => Yii::t('app', '未进行'),
            self::DIS_DELETED => Yii::t('app', '进行中'),
            self::DIS_SUCCESS => Yii::t('app', '已结束'),

        ];
    }
	 
    public static function getGuest($id){
         if(Guest::findOne($id)){
            return Guest::findOne($id)->g_name;
        }else{
            return '';
        }
    }
    public static function getLabel($id){
         if(Label::findOne($id)){
            return Label::findOne($id)->la_name;
        }else{
            return '';
        }
    }
	public static function getCum($id){
         if(CustomSet::findOne($id)){
            return CustomSet::findOne($id)->title;
        }else{
            return '';
        }
    }
}
